from openai import OpenAI
with open("E:\code\Python\Python-token\deepseek.txt","r") as fd:
    api_key = fd.readlines()[0]

with open('news.txt', 'r', encoding='utf-8') as file:
    content = file.read()

    # 替换换行符为 \n（字面字符）
    content = content.replace('\n', '\\n')

    # 删除多余空格（合并多个空格为一个，并去除首尾空格）
    content = ' '.join(content.split())

print(len(content))
client = OpenAI(api_key=api_key, base_url="https://api.deepseek.com")

response = client.chat.completions.create(
    model="deepseek-reasoner",
    max_tokens=4000,  # 默认值可能太小
    stream=False,
    timeout = 60,
    messages=[
        {"role": "system", "content": "你是一个股票新闻分析师，我需要你分析若干股票的新闻,"
                                     +"你需要分析股票的新闻对公司股价的影响，并给出结果。"
                                     +"你的返回结果只有一个数字，数字介于[-100,100]，"
                                     +"数字越大，对股价影响越积极，反之则消极"},
        {"role": "user", "content": content},
    ],
)

print(response.choices[0].message.content)